#pragma once

#include "ddsmanager_global.h"
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
#include "common\configurator\SettingIniFile.h"

#include <QVector>
#include <QHash>
#include <QThread>
#include <QObject>
#include <QMutex>
#include <atomic>
#include "iDDSManager.h"
#include "MessagePublisher.h"
#include "MessageSubscriber.h"
#include "TestPublisher.h"
#include "TestSubscriber.h"
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastrtps/log/Log.h>

template<typename T>
class iObserver;

class iDDSPublisher;
class PublishWrittenResult;
namespace IGTConfig
{
	struct ChannelData;
};
namespace IGTConfig
{
	struct TransferThreadConfig;
	struct TransferInfo;
	struct MqttConnectInfo;
};

class DDSMANAGER_EXPORT DDSManager :public iDDSManager
{
	Q_OBJECT
	Q_PLUGIN_METADATA(IID iDDSManager_iid)
	Q_INTERFACES(iDDSManager)
public:
    DDSManager();
	~DDSManager();
	void init();
	void quit();

	void GetObsByTopic(const IGTConfig::TransferThreadConfig& transferInfo, std::shared_ptr<iObserver<IGTConfig::ChannelData>>& obs);
	void GetObsByTopic(const IGTConfig::TransferThreadConfig& transferInfo, std::shared_ptr<iObserver<IGTConfig::NormalChannelData>>& obs, int type);
	void createPublisher(const IGTConfig::TransferThreadConfig& transferInfo, const uint16_t& type);
	void createPublisher(const IGTConfig::TransferThreadConfig& transferInfo, const uint16_t& type, int other);
	void createPublisherThread(iDDSPublisher* p);
private:
	std::atomic_bool m_bQuit;
private:
	QHash<QString, std::shared_ptr<iObserver<IGTConfig::ChannelData>>> m_topic2Obs_Ch;
	QHash<QString, std::shared_ptr<iObserver<IGTConfig::NormalChannelData>>> m_topic2Obs_Normal_Ch;
	
	QMutex m_mutex;
	std::shared_ptr<TestSubscriber> subscriber = std::make_shared<TestSubscriber>();
	std::shared_ptr<TestPublisher> publisher = std::make_shared<TestPublisher>();
	QVector<QThread*> m_vecThread;
};
